package cn.com.codingce.student.servlet;

import cn.com.codingce.student.entity.Login;
import cn.com.codingce.student.service.ITeacherService;
import cn.com.codingce.student.service.impl.TeacherServiceImpl;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/*
 * 控制器层：接受view请求   并发给Model
 */
@WebServlet("/LoginServlet")
public class LoginServle extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ITeacherService itea = new TeacherServiceImpl();
        //处理登录

        request.setCharacterEncoding("utf-8");
        String teaname = request.getParameter("uname");
        String password = request.getParameter("upwd");
        Login loin = new Login(teaname, password);


        request.getSession().setAttribute("teaname", teaname);
        //调用模型层的登录功能

        int result = itea.login(loin);

        if (result > 0) {
            response.sendRedirect("querybypage");
        } else {
            response.sendRedirect("login.jsp");
        }


    }


}
